package com.svmc.app.task.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import com.svmc.app.task.model.CalenderModel;

public class DateUtils {

	public String getCurrentTime(Calendar calendar) {
		String timecurrent = "";		
		timecurrent = (calendar.get(Calendar.DAY_OF_MONTH) + "/"
				+ (calendar.get(Calendar.MONTH)+1) + "/"
				+ calendar.get(Calendar.YEAR) + "  at    "
				+ calendar.get(Calendar.HOUR_OF_DAY) + ":"
				+ calendar.get(Calendar.MINUTE));
		

		return timecurrent;
	}

	public Calendar setTime(int year, int month, int day, int hour, int minute) {
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.YEAR, year);
		calendar.set(Calendar.MONTH, month);
		calendar.set(Calendar.DAY_OF_MONTH, day);
		calendar.set(Calendar.HOUR_OF_DAY, hour);
		calendar.set(Calendar.MINUTE, minute);
		return calendar;
	}

	public String formatDate(Calendar calendar) {
		String time = "";
		//DateFormat df = new DateFormat();
		SimpleDateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd 'at' HH:mm");
		time = dateformat.format(calendar.getTime());
		//time = df.format("dd/MM/yyyy 'at' hh:mm", calendar).toString();
		//example:  2012/12/06 at 18:11
		return time;

	}
	public CalenderModel ConvertimeDate(String timeString){
		CalenderModel calender = new CalenderModel();
		String day = timeString.substring(8, 10);
		calender.setDay(Integer.parseInt(day));
		String month = timeString.substring(5,7);
		calender.setMonth(Integer.parseInt(month));
		String year = timeString.substring(0,4);
		calender.setYear(Integer.parseInt(year));
		String hour = timeString.substring(14,16);
		calender.setHour(Integer.parseInt(hour));		
		String minute = timeString.substring(17);
		calender.setMinute(Integer.parseInt(minute));
		return calender;
	}
	public String formatDateToShow(Calendar calendar){		
		String time = "";
		//DateFormat df = new DateFormat();
		SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy 'at' HH:mm");
		time = dateformat.format(calendar.getTime());
		//time = df.format("dd/MM/yyyy 'at' hh:mm", calendar).toString();
		//example:  06/12/2012 at 18:11
		return time;
		
	}
	

}
